#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <cmath>
using namespace std;
#define ldb long double
#define ll long long
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define ff first
#define ss second
#define nextLine() {int c = 0; while ((c = getchar()) != 10 && c != EOF); }
const ldb pi = fabsl(atan2l(0.0, -1.0));
const ldb eps = 1e-9;
const int inf = 1 << 28;

string name[100010];
char s[222];
int n;
int a[100010];
int b[100010];
int m;
int we, per[100010];

void load()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		nextLine();
		scanf("%s", s);
		name[i] = s;
		scanf("%d", &a[i]);
		per[i] = i;
	}
	cin >> m;
	for (int i = 0; i < m; i++)
		scanf("%d", &b[i]);
	sort(b, b + m);
	reverse(b, b + m);
	scanf("%s", s);
	for (int i = 0; i < n; i++)
	{
		if (name[i] == s)
			we = i;
	}
}

inline bool better(int i, int j, int c, int d)
{
	return c > d || c == d && name[i] < name[j];
}

inline bool cmp(int i, int j)
{
	if (i == we) return true;
	if (j == we) return false;
	return a[i] > a[j] || a[i] == a[j] && name[i] < name[j];
}

inline bool cmp2(int i, int j)
{
	if (i == we) return false;
	if (j == we) return true;
	return a[i] < a[j] || a[i] == a[j] && name[i] > name[j];
}


void solve()
{
    sort(per, per + n, cmp);
    int our_score = a[we] + b[0];
    int max_pos = 0;
    for (int i = 1; i < n; i++)
    	if (better(per[i], we, a[per[i]] + b[i], our_score)) max_pos++;
   	int cur_pos = 0;
   	for (int i = n - 1; i >= 1; i--)
   		if (better(per[i], we, a[per[i]] + b[n - i - 1], our_score)) cur_pos++;
  	max_pos = min(max_pos, cur_pos);
    sort(per, per + n, cmp2);
    int min_pos = n - 1;
    our_score = a[we] + b[n - 1];
    for (int i = 0; i + 1 < n; i++)
    	if (better(we, per[i], our_score, a[per[i]] + b[i])) min_pos--;
    cur_pos = n - 1;
    for (int i = n - 2; i >= 0; i--)
    	if (better(we, per[i], our_score, a[per[i]] + b[n - i - 1])) cur_pos--;
	min_pos = max(min_pos, cur_pos);    	
    cout << max_pos + 1 << " " << min_pos + 1;
}

#define file "b"

int main()
{
	#ifndef ONLINE_JUDGE
		freopen(file".in", "rt", stdin);
		freopen(file".out", "wt", stdout);
  	#endif
  	load();
  	solve();
  	return 0;
}
